import React, { Component } from 'react';
import { createPortal } from 'react-dom';
import ReactEcharts from 'echarts-for-react';
import darkEchartsTheme from '../../config/theme/darkEchartsTheme';
import echarts from 'echarts';
import { Icon } from 'antd';
import globalStyles from '../../style/common.less';

const modalRoot = document.getElementById('dialog-root');

class TechnologyG60MiddleChart extends Component {
  constructor(props) {
    super(props);
    this.el = document.createElement('TechnologyG60MiddleChart');
    this.state = {
      chartOption: undefined,
      chartHeight: 280,
    };
  }
  componentDidMount() {
    modalRoot.appendChild(this.el);
    echarts.registerTheme('theme_name', darkEchartsTheme);
    this.setChartData();
  }

  setChartData() {
    var category = ['京津冀','长三角','粤港澳'];
    var lineData = [3659.04,4548.21,958.81];
    var barData = [88,71,31];
    // option
    const option = {
      tooltip: {
        trigger: 'axis',
        backgroundColor: 'rgba(255,255,255,0.1)',
        axisPointer: {
          type: 'shadow',
          label: {
            show: true,
            backgroundColor: '#7B7DDC'
          }
        }
      },
      grid: {
        x: '12%',
        width: '65%',
        y: '12%',
      },
      xAxis: {
        data: category,
        axisLine: {
          lineStyle: {
            color: '#B4B4B4'
          }
        },
        splitLine: { show: false },
        axisTick: {
          show: false,
        },
      },
      yAxis: [{
        title:{text:'家'},
        splitLine: { show: false },
        axisLine: {
          lineStyle: {
            color: '#B4B4B4',
          }
        },
        axisLabel: {
          formatter: '{value}',
        }
      },
      {
        title:{text:'亿元'},
        splitLine: { show: false },
        axisLine: {
          lineStyle: {
            color: '#B4B4B4',
          }
        },
        axisLabel: {
          formatter: '{value}亿元',
        }
      }],
      series: [{
        name: '独角兽企业估值',
        type: 'line',
        smooth: true,
        showAllSymbol: true,
        symbol: 'emptyCircle',
        symbolSize: 8,
        yAxisIndex: 1,
        itemStyle: {
          normal: {
            color: '#F02FC2'
          },
        },
        data: lineData
      },
      {
        name: '独角兽企业数量',
        type: 'bar',
        barWidth: 10,
        itemStyle: {
          normal: {
            barBorderRadius: 5,
            color: new echarts.graphic.LinearGradient(
              0, 0, 0, 1,
              [
                { offset: 0, color: '#956FD4' },
                { offset: 1, color: '#3EACE5' }
              ]
            )
          }
        },
        data: barData
      }
      ]
    };
    this.setState({ chartOption: option });
  }

  render() {
    const { style, width, height } = this.props;
    const dtTitle = `独角兽企业数量及估值`;
    const { chartOption } = this.state;
    return createPortal(
      <div
        style={{
          ...style,
          display: 'flex',
          flexDirection: 'column',
          width: width,
          height: height,
          color: '#fff',
          backgroundColor: 'rgba(0,0,0,0.6)',
          boxShadow: '0 1px 2px rgba(0,0,0,0.16), 0 1px 2px rgba(0,0,0,0.23)',
        }}
      >
        <div
          style={{
            lineHeight: '35px',
            height: 35,
            borderBottom: '1px solid rgb(238, 238, 238,0.2)',
            textAlign: 'center',
            fontWeight: 'bold'
          }}
        >
          <div style={{ float: 'left', marginLeft: 6, fontSize: 15 }}><div style={{ float: 'left', width: 5, height: 35, marginRight: 10, backgroundColor: 'rgba(63,177,277,1)', }} />{dtTitle}</div>
          <div style={{ float: 'right', marginRight: 8 }}>
            {/* <Icon
              type="close"
              className={`${globalStyles.cursor_style_pointer}`}
              style={{ fontSize: 18 }}
              onClick={this.props.onClose}
            /> */}
          </div>
        </div>
        <div style={{ margin: '3px 8px 3px 8px' }}>
          <div>
            {chartOption !== undefined && (
              <ReactEcharts
                option={chartOption}
                notMerge={true}
                lazyUpdate={true}
                theme={'theme_name'}
                style={{ height: this.state.chartHeight }}
              />
            )}
          </div>
        </div>
      </div>,
      this.el
    );
  }
}

export default TechnologyG60MiddleChart;
